package com.examplemartin.jpademo.service.admin;

import com.examplemartin.jpademo.dao.admin.OperatorLogDao;
import com.examplemartin.jpademo.pojo.admin.OperatorLogPO;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class OperatorLogService {

  @Resource
  private OperatorLogDao operatorLogDao;

  public void saveLog(OperatorLogPO log) {
    operatorLogDao.save(log);

  }

  public void deleteLogAll() {
    operatorLogDao.deleteAll();
  }

  public List<OperatorLogPO> findAllPage(Pageable page) {
    if (page == null) {
      page = PageRequest.of(0, 10);
    }

    Page<OperatorLogPO> all = operatorLogDao.findAll(page);
    List<OperatorLogPO> content = all.getContent();
    return content;

  }

  // 计算日志总数
  public Long countAll(){
    return operatorLogDao.count();
  }

  // 删除日志
  public void deleteLogById(Long id){
    operatorLogDao.deleteById(id);
  }
}
